﻿using SnmpForm.SnmpWrapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;

namespace SnmpForm.ApBatchConfig
{
    class BatchSyncTask:BatchTask
    {
        public BatchSyncTask(FrmApBatchConfig objForm,
            List<BusinessWrapper.Ap> aps)
            : base(objForm, aps)
        {
        }

        public override void ApAction(BusinessWrapper.Ap ap)
        {
            string strStatus = "";
            try
            {
                //从Ap扫描信息到管理端
                ap.ScanApAllInfo();
                // 保存到数据库中
                BusinessWrapper.User.Instance.ModifyAp(ap.GetInfo());
                BusinessWrapper.User.Instance.ModifyWirelessInfo(ap);
                BusinessWrapper.User.Instance.ModifyWirelessSecurity(ap);
                BusinessWrapper.User.Instance.ModifyAdvanceTools(ap);
                strStatus = "成功";
            }
            catch (Lextm.SharpSnmpLib.Messaging.TimeoutException ex)
            {
                Console.WriteLine(ex.Message.ToString());
                strStatus = "同步超时";
            }
            catch (SocketException ex)
            {
                Console.WriteLine(ex.Message.ToString());
                strStatus = "连接异常";
            }
            catch (SnmpErrorException ex)
            {
                strStatus = ("请求错误" + ex.Message);
            }
            catch (ApSnmpException ex)
            {
                strStatus = ex.Message;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
                strStatus = "异常" + ex.Message;
            }

            UpdateStatus(ap, strStatus);
        }
    }
}
